package demo10;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-12-08
 * Time: 14:19
 */
class Country {
    public int id;
    public int goldMedal;
    public int medal;
    public int population;
    public int goldMedalPer;
    public int medalPer;
    public Country(int id) {
        this.id = id;
    }
    public int rank = 5;
    public int list = 0;
}
class SortByGoldMedal implements Comparator<Country> {
    @Override
    public int compare(Country o1, Country o2) {
        return o1.goldMedal - o2.goldMedal;
    }
}
class SortByMedal implements Comparator<Country> {
    @Override
    public int compare(Country o1, Country o2) {
        return o1.medal - o2.medal;
    }
}
class SortByMedalPer implements Comparator<Country> {
    @Override
    public int compare(Country o1, Country o2) {
        return (o1.medalPer - o2.medalPer);
    }
}
class SortByGoldMedalPer implements Comparator<Country> {
    @Override
    public int compare(Country o1, Country o2) {
        return (o1.goldMedalPer - o2.goldMedalPer);
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Country[] countries = new Country[n];
        int m = scanner.nextInt();


        for (int i = 0; i < n; i++) {
            countries[i] = new Country(i);
            countries[i].goldMedal = scanner.nextInt();
            countries[i].medal = scanner.nextInt();
            countries[i].population = scanner.nextInt();
            countries[i].goldMedalPer = countries[i].goldMedal * 10000 / countries[i].population;
            countries[i].medalPer = countries[i].medal * 10000 / countries[i].population;
        }
        int[] num = new int[m];
        for (int i = 0; i < m; i++) {
            num[i] = scanner.nextInt();
        }
        sort1(countries);
        sort2(countries);
        sort3(countries);
        sort4(countries);


        for (int i = 0; i < m; i++) {
            if (i == 0) {
                System.out.print(countries[num[i]].rank + ":" + countries[num[i]].list);
            } else {
                System.out.print(" " + countries[num[i]].rank + ":" + countries[num[i]].list);
            }

        }
    }

    private static void sort4(Country[] countries) {
        SortByMedalPer sort = new SortByMedalPer();
        for (int i = 0; i < countries.length - 1; i++) {
            for (int j = 0; j < countries.length - 1 - i; j++) {
                if (sort.compare(countries[j], countries[j + 1]) < 0) {
                    Country country = countries[j];
                    countries[j] = countries[j + 1];
                    countries[j + 1] = country;
                }
            }
        }
        for (int i = 1; i <= countries.length; i++) {
            if (i == 1) {
                if (countries[i - 1].rank > i) {
                    countries[i - 1].rank = i;
                    countries[i - 1].list = 4;
                }
            } else {
                if (countries[i - 1].goldMedal == countries[i - 2].goldMedal) {
                    if (countries[i - 1].rank > i - 1) {
                        countries[i - 1].rank = i - 1;
                        countries[i - 1].list = 4;
                    }
                } else {
                    if (countries[i - 1].rank > i - 1) {
                        countries[i - 1].rank = i - 1;
                        countries[i - 1].list = 4;
                    }
                }
            }
        }
    }

    private static void sort3(Country[] countries) {
        SortByGoldMedalPer sort = new SortByGoldMedalPer();
        for (int i = 0; i < countries.length - 1; i++) {
            for (int j = 0; j < countries.length - 1 - i; j++) {
                if (sort.compare(countries[j], countries[j + 1]) < 0) {
                    Country country = countries[j];
                    countries[j] = countries[j + 1];
                    countries[j + 1] = country;
                }
            }
        }
        for (int i = 1; i <= countries.length; i++) {
            if (i == 1) {
                if (countries[i - 1].rank > i) {
                    countries[i - 1].rank = i;
                    countries[i - 1].list = 3;
                }
            } else {
                if (countries[i - 1].goldMedal == countries[i - 2].goldMedal) {
                    if (countries[i - 1].rank > i - 1) {
                        countries[i - 1].rank = i - 1;
                        countries[i - 1].list = 3;
                    }
                } else {
                    if (countries[i - 1].rank > i - 1) {
                        countries[i - 1].rank = i - 1;
                        countries[i - 1].list = 3;
                    }
                }
            }
        }
    }

    private static void sort2(Country[] countries) {
        SortByMedal sort= new SortByMedal();
        for (int i = 0; i < countries.length - 1; i++) {
            for (int j = 0; j < countries.length - 1 - i; j++) {
                if (sort.compare(countries[j], countries[j + 1]) < 0) {
                    Country country = countries[j];
                    countries[j] = countries[j + 1];
                    countries[j + 1] = country;
                }
            }
        }
        for (int i = 1; i <= countries.length; i++) {
            if (i == 1) {
                if (countries[i - 1].rank > i) {
                    countries[i - 1].rank = i;
                    countries[i - 1].list = 2;
                }
            } else {
                if (countries[i - 1].goldMedal == countries[i - 2].goldMedal) {
                    if (countries[i - 1].rank > i - 1) {
                        countries[i - 1].rank = i - 1;
                        countries[i - 1].list = 2;
                    }
                } else {
                    if (countries[i - 1].rank > i - 1) {
                        countries[i - 1].rank = i - 1;
                        countries[i - 1].list = 2;
                    }
                }
            }
        }

    }

    private static void sort1(Country[] countries) {
        SortByGoldMedal sort = new SortByGoldMedal();
        for (int i = 0; i < countries.length - 1; i++) {
            for (int j = 0; j < countries.length - 1 - i; j++) {
                if (sort.compare(countries[j], countries[j + 1]) < 0) {
                    Country country = countries[j];
                    countries[j] = countries[j + 1];
                    countries[j + 1] = country;
                }
            }
        }
        for (int i = 1; i <= countries.length; i++) {
            if (i == 1) {
                if (countries[i - 1].rank > i) {
                    countries[i - 1].rank = i;
                    countries[i - 1].list = 1;
                }
            } else {
                if (countries[i - 1].goldMedal == countries[i - 2].goldMedal) {
                    if (countries[i - 1].rank > i - 1) {
                        countries[i - 1].rank = i - 1;
                        countries[i - 1].list = 1;
                    }
                } else {
                    if (countries[i - 1].rank > i) {
                        countries[i - 1].rank = i;
                        countries[i - 1].list = 1;
                    }
                }
            }
        }
    }
}
